package top.malegod.consumer;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import top.malegod.utils.RedisUtils;
import top.malegod.utils.SendMessageUtils;

/**
 * Create by IntelliJ IDEA
 *
 * @author: AbelEthan
 * @date-Time: 2018/5/22 16:18
 * @description:
 */
public class PhoneCodeConsumer implements MessageListener{

  private final Long EXPIRE_TIME = 15L * 60;

  @Autowired
  private RedisUtils redisUtils;

  @Override
  public void onMessage(Message message) {
    try {
      String s = new String(message.getBody(), "UTF-8");
      int code = (int)((Math.random() * 9 + 1) * 100000);
      redisUtils.set(s,code,EXPIRE_TIME);
      SendMessageUtils.sendCode(s, String.valueOf(code));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
